Imports System.IOImports System.CollectionsPublic Class ImageViewer ' private member variables Private mFolder As String Private mImageList As ArrayList Private mImagePosition As Integer Private mPreviousImage As Image Private mCurrentImage As Image Private mNextImage As Image ''' <summary> ''' Default Constructor ''' </summary> ''' <remarks></remarks> Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. End Sub ''' <summary> ''' Default load event handler ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub ImageViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' do nothing End Sub ''' <summary> ''' Open the folder browse dialog and load ''' the initial images ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click ' Label the folder browser dialog Me.folderBrowserDialog1.Description = "Select the image directory." ' disable create folder feature of folder browser Me.folderBrowserDialog1.ShowNewFolderButton = False ' display the folder browser Dim result As DialogResult = folderBrowserDialog1.ShowDialog() If result = DialogResult.OK Then ' on okay, set the image folder to the ' folder browser's selected path mFolder = folderBrowserDialog1.SelectedPath If (Not String.IsNullOrEmpty(mFolder)) Then txtImageDirectory.Text = mFolder Else ' exit if the user cancels Return End If ' initialize the image arraylist mImageList = New ArrayList() ' loop through the image directory ' and find all of the image files ' add the found files to the image ' list - add other image types if ' necessary Dim Dir As New DirectoryInfo(mFolder) Dim f As FileInfo For Each f In Dir.GetFiles("*.*") Select Case (f.Extension.ToUpper()) Case ".JPG" mImageList.Add(f.FullName) Case ".BMP" mImageList.Add(f.FullName) Case ".GIF" mImageList.Add(f.FullName) Case Else ' skip file End Select Next ' set the starting position to 0 ' and call the set images method ' to load the pictures mImagePosition = 0 SetImages() End If End Sub ''' <summary> ''' This function is used to set the previous, ''' current, and next images into the ''' correct picture boxes ''' </summary> ''' <remarks></remarks> Private Sub SetImages() ' clear any existing images ' memory will be an issue if ' cycling through a large ' number of images mPreviousImage = Nothing mNextImage = Nothing mCurrentImage = Nothing ' set the previous image If mImagePosition > 0 Then Try ' set delegate Dim prevCallback As Image.GetThumbnailImageAbort = _ New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) ' get the previous image Dim prevBmp As _ New Bitmap(mImageList(mImagePosition - 1).ToString()) ' thumbnail the image to the size ' of the picture box mPreviousImage = _ prevBmp.GetThumbnailImage(160, 100, _ prevCallback, IntPtr.Zero) ' set the picture box image picPreviousImage.Image = mPreviousImage ' clear everything out prevBmp = Nothing prevCallback = Nothing mPreviousImage = Nothing Catch 'stall if it hangs, the user can retry End Try Else ' at the limit clear the ' image picPreviousImage.Image = Nothing End If ' set current image If mImagePosition < mImageList.Count Then Try ' set delegate Dim currentCallback = _ New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) ' get the current image Dim currentBmp As _ New Bitmap(mImageList(mImagePosition).ToString()) ' thumbnail the image to the size ' of the picture box mCurrentImage = _ currentBmp.GetThumbnailImage(320, 200, currentCallback, IntPtr.Zero) ' set the picture box image picCurrentImage.Image = mCurrentImage ' clear everything out currentBmp = Nothing mCurrentImage = Nothing currentCallback = Nothing Catch 'stall if it hangs, the user can retry End Try End If ' set next image If mImagePosition < mImageList.Count - 1 Then Try ' set delegate Dim nextCallback As _ New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) ' get the next image Dim nextBmp As _ New Bitmap(mImageList(mImagePosition 1).ToString()) ' thumbnail the image to the size ' of the picture box mNextImage = _ nextBmp.GetThumbnailImage(160, 100, nextCallback, IntPtr.Zero) ' set the picture box image picNextImage.Image = mNextImage ' clear everything out nextBmp = Nothing nextCallback = Nothing mNextImage = Nothing Catch 'stall if it hangs, the user can retry End Try Else ' at the limit clear the ' image picNextImage.Image = Nothing End If ' call for garbage collection GC.Collect() End Sub ''' <summary> ''' Thumbnail image abort target ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Public Function ThumbnailCallback() As Boolean Return False End Function ''' <summary> ''' Set the image position and reset all ''' of the images when the previous image ''' button is clicked ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub btnPreviousImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreviousImage.Click If (mImagePosition >= 0 And Not picPreviousImage.Image Is Nothing) Then mImagePosition -= 1 SetImages() End If End Sub ''' <summary> ''' Set the image position and reset all ''' of the images when the next image ''' button is clicked ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub btnNextImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextImage.Click If (mImagePosition <= (mImageList.Count - 2)) Then mImagePosition = 1 SetImages() End If End Sub ''' <summary> ''' Open the current image using the default ''' program per the user's file associations ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub btnOpenImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenImage.Click System.Diagnostics.Process.Start(mImageList(mImagePosition).ToString()) End SubEnd Class
下载vb 具有预览功能的图像查看器用户控件用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论